prep_data() function imports and combines the data contained in the vd, vds, and vde file. This generates a single long R dataframe (tibble). All strings are in lower case, missing data is replaced with NA (or “annual” for timeslice).demos_001, and display the data in an interactive table demos_001We can compare results produced by VedaR to those produced from tables generated by the Veda graphical-user interface.
Here, we compare the output of the “All costs” Veda table to comparable output from VedaR.
| Attribute | Commodity | Process | Period | Region | Pv |
|---|---|---|---|---|---|
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | EXPCOA1 | 2005 | REG1 | -3154.440 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | EXPCOA1 | 2006 | REG1 | -3154.440 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | IMPCOA1 | 2005 | REG1 | 17772.345 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | IMPCOA1 | 2006 | REG1 | 17772.345 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | MINCOA1 | 2005 | REG1 | 12147.537 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | MINCOA1 | 2006 | REG1 | 12147.537 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | MINCOA2 | 2005 | REG1 | 5061.474 |
| Cost_Flo [Annual flow costs (including import/export prices)] | COA | MINCOA2 | 2006 | REG1 | 5061.474 |
| Cost_Fom [Annual fixed operating and maintenance costs] |
|
DTPSCOA | 2005 | REG1 | 2823.992 |
| Cost_Fom [Annual fixed operating and maintenance costs] |
|
DTPSCOA | 2006 | REG1 | 2823.992 |
| Cost_Inv [Annual investment costs] |
|
DTPSCOA | 2005 | REG1 | 11057.162 |
| Cost_Inv [Annual investment costs] |
|
DTPSCOA | 2006 | REG1 | 11057.162 |
| Cost_Salv [Salvage values of capacities at EOH+1] |
|
DTPSCOA |
|
REG1 | 113069.549 |
| attribute | commodity | process | period | region | pv |
|---|---|---|---|---|---|
| cost_flo | coa | expcoa1 | 2005 | reg1 | -3154.440 |
| cost_flo | coa | expcoa1 | 2006 | reg1 | -3154.440 |
| cost_flo | coa | impcoa1 | 2005 | reg1 | 17772.345 |
| cost_flo | coa | impcoa1 | 2006 | reg1 | 17772.345 |
| cost_flo | coa | mincoa1 | 2005 | reg1 | 12147.537 |
| cost_flo | coa | mincoa1 | 2006 | reg1 | 12147.537 |
| cost_flo | coa | mincoa2 | 2005 | reg1 | 5061.474 |
| cost_flo | coa | mincoa2 | 2006 | reg1 | 5061.474 |
| cost_fom | NA | dtpscoa | 2005 | reg1 | 2823.992 |
| cost_fom | NA | dtpscoa | 2006 | reg1 | 2823.992 |
| cost_inv | NA | dtpscoa | 2005 | reg1 | 11057.162 |
| cost_inv | NA | dtpscoa | 2006 | reg1 | 11057.162 |
| cost_salv | NA | dtpscoa | NA | reg1 | 113069.549 |
make_res() visualises the system of the TIMES solution as a Sankey diagram.res_all <- make_res(dat = demos_007,
region_select = "reg1",
period_select = 2020,
node_labels = process_description,
edge_labels = commodity_description,
sankey_width = 1000,
sankey_height = 1000,
font_size = 10)
## <quosure>
## expr: ^process_description
## env: global
res_all
igraph package is one of these https://igraph.org/r/html/latest/.make_graph_from_veda_df() transforms the veda data tibble that was produced by prep_data() into an igraph object. If the data contains only a single year, edge weights are assigned based on var_fin and var_fout attributes.g <- demos_007 %>%
filter(period == 2020,
region == "reg1") %>%
make_graph_from_veda_df(node_labels = process,
edge_labels = commodity
)
# print edge weights
print("Edge weights")
## [1] "Edge weights"
E(g)$weight
## [1] 2624.76319 3091.68686 47.10103 458.01812 1255.69200
## [6] 1842.83904 2669.57081 954.51146 478946.18800 634340.87421
## [11] 1255.69200 4799.06000 6356.12098 985.97983 15.02114
## [16] 146.06803 900.38520 743.56800 177.23310 116.70990
## [21] 240.50400 989.09130 271.82160 9588.59790 146.07973
## [26] 1420.50335 1255.69200 2671.26734 2450.22180 4963.26911
## [31] 5121.48914 3596.80600 6050.35198 378990.19673
We can compute all simple paths from a given node using the igraph function all_simple_paths() (or between two nodes if the to = argument is specified)
Here, we create an object all_mincoa1_paths that is the list of all paths starting from the mincoa1 process.
all_mincoa1_paths <- all_simple_paths(g, from = "mincoa1")
all_mincoa1_paths
## [[1]]
## + 2/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa
##
## [[2]]
## + 3/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctecoa00
##
## [[3]]
## + 4/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctecoa00 dtpselc
##
## [[4]]
## + 5/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctecoa00 dtpselc
## [5] tpselc_end_process
##
## [[5]]
## + 4/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctecoa00 elcco2_end_process
##
## [[6]]
## + 3/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctncoa00
##
## [[7]]
## + 4/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctncoa00 dtpselc
##
## [[8]]
## + 5/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctncoa00 dtpselc
## [5] tpselc_end_process
##
## [[9]]
## + 4/30 vertices, named, from ca65929:
## [1] mincoa1 fte-elccoa elctncoa00 elcco2_end_process
##
## [[10]]
## + 2/30 vertices, named, from ca65929:
## [1] mincoa1 dtpscoa
##
## [[11]]
## + 3/30 vertices, named, from ca65929:
## [1] mincoa1 dtpscoa tpscoa_end_process
##
## [[12]]
## + 2/30 vertices, named, from ca65929:
## [1] mincoa1 expcoa1
The vedar function check_in_paths() provides a means of checking whether a string expression is included in the set of paths. The string needs to be passed as a (regular expression)[https://www.petefreitag.com/cheatsheets/regex/]
If all export processes include the string “exp”, you can check if the string “exp” appears in the set of paths “all_mincoa1_paths” using the following command.
check_in_path("(exp)", all_mincoa1_paths)
## [[1]]
## [1] FALSE FALSE
##
## [[2]]
## [1] FALSE FALSE FALSE
##
## [[3]]
## [1] FALSE FALSE FALSE FALSE
##
## [[4]]
## [1] FALSE FALSE FALSE FALSE FALSE
##
## [[5]]
## [1] FALSE FALSE FALSE FALSE
##
## [[6]]
## [1] FALSE FALSE FALSE
##
## [[7]]
## [1] FALSE FALSE FALSE FALSE
##
## [[8]]
## [1] FALSE FALSE FALSE FALSE FALSE
##
## [[9]]
## [1] FALSE FALSE FALSE FALSE
##
## [[10]]
## [1] FALSE FALSE
##
## [[11]]
## [1] FALSE FALSE FALSE
##
## [[12]]
## [1] FALSE TRUE
igraph functions. Here, we check whether an “exp” process is included in the paths that are linked to the “coa” commodity as follows#find all coa edges
coa_edges <- which(E(g)$commodity == "coa")
#find the start vertices of the coa commodity edges
coa_start_vertices <- ends(g, coa_edges)[,1]
#find all the paths that are linked to the coa_start_vertices
all_coa_paths <- all_simple_paths(g, from = unique(coa_start_vertices))
#check if the string "exp" appears in the set of paths that project from coa_start_vertices
print("Check if 'exp' is in all_coa_paths")
## [1] "Check if 'exp' is in all_coa_paths"
check_in_path("(exp)", all_coa_paths)
## [[1]]
## [1] FALSE FALSE
##
## [[2]]
## [1] FALSE FALSE FALSE
##
## [[3]]
## [1] FALSE FALSE FALSE FALSE
##
## [[4]]
## [1] FALSE FALSE FALSE FALSE FALSE
##
## [[5]]
## [1] FALSE FALSE FALSE FALSE
##
## [[6]]
## [1] FALSE FALSE FALSE
##
## [[7]]
## [1] FALSE FALSE FALSE FALSE
##
## [[8]]
## [1] FALSE FALSE FALSE FALSE FALSE
##
## [[9]]
## [1] FALSE FALSE FALSE FALSE
##
## [[10]]
## [1] FALSE FALSE
##
## [[11]]
## [1] FALSE FALSE FALSE
##
## [[12]]
## [1] FALSE TRUE
#check if the string "dist" appears in the set of paths that project from coa_start_vertices
print("Check if 'dist' is in all_coa_paths")
## [1] "Check if 'dist' is in all_coa_paths"
check_in_path("(dist)", all_coa_paths)
## [[1]]
## [1] FALSE FALSE
##
## [[2]]
## [1] FALSE FALSE FALSE
##
## [[3]]
## [1] FALSE FALSE FALSE FALSE
##
## [[4]]
## [1] FALSE FALSE FALSE FALSE FALSE
##
## [[5]]
## [1] FALSE FALSE FALSE FALSE
##
## [[6]]
## [1] FALSE FALSE FALSE
##
## [[7]]
## [1] FALSE FALSE FALSE FALSE
##
## [[8]]
## [1] FALSE FALSE FALSE FALSE FALSE
##
## [[9]]
## [1] FALSE FALSE FALSE FALSE
##
## [[10]]
## [1] FALSE FALSE
##
## [[11]]
## [1] FALSE FALSE FALSE
##
## [[12]]
## [1] FALSE FALSE
igraph allows you to extract a range of graph theory metrics from your TIMES graph.